public class Main {
    public static void main(String[] args) {
        System.out.println(myPow(2, 10));
    }

    /**
     * x的完全平方根
     * @param x
     * @return
     */
    public static int mySqrt(int x) {
        long l=0,r=x,res=-1;
        while(l<=r){
            long mid=(r+l)/2;
            if(mid*mid>x){
                r=mid-1;
            }else{
                l=mid+1;
                res=mid;
            }
        }
        return (int)res;
    }

    /**
     * pow(x,n)
     * @param x
     * @param n
     * @return
     */
    public static double myPow(double x, int n) {
        return n<0?1.0/pow(x,n):pow(x,n);
    }
    public static double pow(double x,int n){
        if(n==0){
            return 1;
        }
        int cnt=n/2;
        double res=pow(x,cnt);
        return n%2==0?res*res:res*res*x;
    }
    /**
     * 两两交换链表中的节点
     * @param head
     * @return
     */
    public static ListNode swapPairs(ListNode head) {
        if(head==null||head.next==null){
            return head;
        }
        ListNode newHead=swapPairs(head.next.next);
        ListNode ret=head.next;
        head.next=newHead;
        ret.next=head;
        return ret;
    }

    /**
     * 反转链表
     * @param head
     * @return
     */
    public static ListNode reverseList(ListNode head) {
        //递归
        // if(head==null||head.next==null){
        //     return head;
        // }
        // ListNode newHead=reverseList(head.next);
        // head.next.next=head;
        // head.next=null;
        // return newHead;
        if(head==null){
            return head;
        }
        ListNode cur=head.next;
        head.next=null;
        while(cur!=null){
            ListNode curN=cur.next;
            cur.next=head;
            head=cur;
            cur=curN;
        }
        return head;
    }
}
